#include <string.h>

int memcmp(const void *cs, const void *ct, size_t count) {
	unsigned char *su1 = (unsigned char *) cs;
	unsigned char *su2 = (unsigned char *) ct;
	int res = 0;

	for (; count > 0; ++su1, ++su2, count--) {
		if ((res = *su1 - *su2) != 0) {
			break;
		}
	}
	return res;
}

#ifdef _TEST_
#include <stdio.h>

int main() {
	char str1[256];
	char str2[256];
	int n;
	size_t len1, len2;
	printf("Enter a sentence: ");
	gets(str1);
	printf("Enter another sentence: ");
	gets(str2);
	len1 = strlen(str1);
	len2 = strlen(str2);
	n = memcmp(str1, str2, len1 > len2 ? len1 : len2);
	if (n > 0)
		printf ("'%s' is greater than '%s'.\n", str1, str2);
	else if (n < 0)
		printf ("'%s' is less than '%s'.\n", str1, str2);
	else
		printf ("'%s' is the same as '%s'.\n", str1, str2);
	return 0;
}

#endif
